<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>订单详情 - bilibili</title>
    <script src="http://47.106.66.89:8080/js/vue.min.js"></script>
    <!-- ele 的引入放在vue下面-->
    <link href="http://47.106.66.89:8080/js/ele-2.15.7/theme-chalk/index.css" rel="stylesheet">
    <script src="http://47.106.66.89:8080/js/ele-2.15.7/index.js"></script>
    <script src="http://47.106.66.89:8080/js/axios.min.js"></script>
    <script src = 'plug-in/jquery-2.2.0.min.js' type='text/javascript'></script>
    <script src="js/product-common.js"></script>
    <link href="css/ordercenter.css" rel="stylesheet">
    <link href="css/product-common.css" rel="stylesheet">
    <link href="css/login.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/jsqr/dist/jsQR.js"></script>
</head>
<body>
    <div id="app">
        <product @logined="logined"></product>

        <div class="container">
            <div v-for="o in orders">
                <div class="order-header">
                    <div class="order-info">
                        <span>创建时间：2025-04-12 11:10:48</span>
                        <span>订单号：8001038931306095</span>
                    </div>
                </div>

                <div class="order-card" style="display: flex; justify-content: space-between;">
                    <div style="display: flex;">
                        <img :src="o.image" style="width: 100px;">
                        <div>
                            <div class="order-title">{{o.name}}</div>
                            <div class="order-submit">下单时间：{{o.ordertime.toString().replace('T', ' ').split(".")[0]}}</div>
                        </div>
                    </div>

                    <div class="order-detail">
                        <div class="ticket-info" style=" gap: 60px;">
                            <span class="ticket-quantity">{{o.nums}}</span>
                            <span class="ticket-price">￥{{o.total}}</span>
<!--                            <span class="ticket-type">电子票</span>-->
<!--                            <span class="delivery-info">无需配送</span>-->
                        </div>
                    </div>
                    <div>
                        <div class="state">{{o.state == 1 ? "待发货" : o.state == 0 ? "未支付" : "已取消"}}</div>
                        <br>
                        <el-button v-if="o.state == 1" class="order-btn" style="width: 100px;"@click="canelOrder(o.id)">取消订单</el-button>
                    </div>
                </div>
            </div>

            <div class="pagination">
                <el-pagination
                        :page-size="size"
                        background
                        layout="prev, pager, next"
                        :total="total"
                        @prev-click="prevPage"
                        @next-click="nextPage"
                        @current-change="currentChange">
                </el-pagination>
            </div>

        </div>
    </div>
</body>
<script>
    var v = new Vue({
        el : "#app",
        data : {
            myinfo: {},
            orders:{},
            page: 1,
            size: 3,
            total: 0,
        },
        created() {
            this.getOrderById()
            this.getOrderCountById()
        },
        methods : {
            logined(myinfo){
                this.myinfo = myinfo;
            },
            getOrderById(){
                axios.get("b-shopping/order/getOrderById", {
                    params:{
                        id : location.search.split("=")[1].split("&")[0],
                        page: this.page,
                        size: this.size,
                    }
                }).then(res=>{
                    if (res.data.code == 1) {
                        this.orders = res.data.data
                    }else{
                        this.$alert(res.data.msg)
                    }
                })
            },
            getOrderCountById(){
                axios.get("b-shopping/order/getOrderCountById"+location.search).then(res=>{
                    this.total = res.data;
                })
            },
            prevPage(){
                this.page -= 1;
                this.getOrderById();
            },
            nextPage(){
                this.page += 1
                this.getOrderById();
            },
            currentChange(val){
                this.page = val
                this.getOrderById();
            },
            canelOrder(id){
                this.$confirm('确定取消该订单吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(()=>{
                    axios.get("b-shopping/order/canelOrder?id="+id).then(res=>{
                        this.orders.forEach((item)=>{
                            if(item.id == id){
                                item.state = 2;
                            }
                        })
                        this.$alert(res.data.msg)
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消操作'
                    });
                })

            }
        }
    })
</script>
</html>